<?php

namespace App\Http\Controllers;

use App\Exceptions\ApiException;
use App\Http\Requests\BasicRequest;
use App\Http\Requests\IndexCityHouseRequest;
use App\Http\Requests\IndexCouncilComplaintsParentSubmitRequest;
use App\Http\Requests\IndexRequest;
use App\Libraries\msg\Push;
use App\Mail\Basic;
use App\Models\Area;
use App\Models\Banner;
use App\Models\ClientUser;
use App\Models\ClientUserHouse;
use App\Models\ClientUserIntegral;
use App\Models\ClientUserMessage;
use App\Models\ClientUserRelationship;
use App\Models\ClientUserMessagesType;
use App\Models\ClientUserTicket;
use App\Models\Config;
use App\Models\HouseDistrict;
use App\Models\Message;
use App\Models\NeighborCouncilComplaints;
use App\Models\NeighborCouncilList;
use App\Models\NeighborCouncilPublicity;
use App\Models\NeighborCouncilSurvey;
use App\Models\NeighborCouncilSurveyAnswer;
use App\Models\News;
use App\Models\House;
use App\Models\Service;
use App\Models\ServiceTeam;
use App\Models\ServiceTeamDetail;
use App\Models\ServiceCompanyOrganization;
use App\Models\ServiceType;
use App\Models\ShopSeckillGoods;
use App\Models\ShopGroupGoods;
use App\Models\LoadingImg;
use App\Http\Requests\LoadingImgRequest;
use App\Models\ShopStore;
use App\Models\Withdraw;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class IndexController extends CommonController
{
	public function add_house(){
         set_time_limit(0);
         $houseClass= new HouseDistrict();
	     $house=DB::table('house')->where(['status'=>1])->select('house_id')->get()->each(function($val,$k) use($houseClass){
               $id=$val->house_id;
               $update = array(
                   'create_time' => date('Y-m-d H:i:s'),
                   'update_time' => date('Y-m-d H:i:s'),
                   'status' => 2,
               );
               $house_list = $houseClass->parent($id);
               $update['house_detail'] = $house_list->reverse()->values()->pluck('name')->implode('');
               foreach ($house_list as $v) {
                    if ($v->type == 2) {
                         $update['village_id'] = $v->id;
                         $update['area_id'] = $v->area_id;
                         $update['city_id'] = $v->city_id;
                         $update['province_id'] = $v->province_id;
                    } else if ($v->type == 3) {
                         $update['budding_id'] = $v->id;
                    } else if ($v->type == 7) {
                         $update['partition_id'] = $v->id;
                    } else if($v->type == 5){
                         $update['floor_id'] = $v->id;
                    }
               };
               DB::table('house')->where(['house_id' => $id])->update($update);
          });
	     return json_success('OK');
	}

	//引导页图片
	public function loading_img(LoadingImgRequest $request){
        $mobile_type = $request->input('mobile_type');

        $var = LoadingImg::where(['mobile_type'=>$mobile_type])->orderBy('sort','desc')->get();
        return json_success('OK',$var);
    }
	public function index(IndexRequest $request){
		$house_id = $request->input('house_id');
		$ticket = $request->input('ticket');
		$uid = ClientUserTicket::where(['ticket'=>$ticket])->value('uid');

		$lat = $request->input('lat');
		$lng = $request->input('lng');
		// 如果有传值，就根据传值来获取小区信息，否则就根据经纬度来

		if(intval($house_id)){
			$house_geo = HouseDistrict::find($house_id);
			$city_id = $house_geo->city_id;
			$house = $house_geo->name;
			//判断是否绑定
			$binded_check = DB::table('client_user_house')->where(['uid'=>$uid,'village_id'=>$house_id])->first();
			if($binded_check){
				$binded=1;
			}else{
				$binded=0;
			}
		}else{
			$primary_house = ClientUserHouse::where(['uid'=>$uid])->orderBy('primary','desc')->value('house_id');
			
			// 如果绑定了房屋，就显示主房屋，没绑定就获取定位
			if($primary_house){
				$house_geo = HouseDistrict::firstOrNew(['id'=>$primary_house])->detail()->details->first();
				$city_id = $house_geo->city_id;
				$house = $house_geo->name;
				$house_id = $house_geo->id;
				$binded = 1;
			}else{
				$house_geo = HouseDistrict::select(DB::raw('*,round(6378.138*2*asin(sqrt(pow(sin((' . $lat . '*pi()/180-lat*pi()/180)/2),2)+cos(' . $lat . '*pi()/180)*cos(lat*pi()/180)* pow(sin((' . $lng . '*pi()/180-lng*pi()/180)/2),2)))*1000) as distance'))->district()->orderBy('distance','asc')->first();
				$house = $house_geo->name;
				$city_id = $house_geo->city_id;
				$house_id = $house_geo->id;
				$binded = 0;
			}
		}
		
		$city = DB::table('area')->where(['id'=>$city_id])->value('name');
		// 首页轮播图
		$banner = Banner::where(['type'=>0,'house_id'=>$house_id])->get();
		// 未读消息总数
		$message_unview_count = group99(ClientUserMessage::where(['uid'=>$this->uid,'viewed'=>0])->count());
		// 社区调查，最新4条，物业调查
        $village_id =  ClientUserHouse::where(['uid'=>$uid])->orderBy('primary','desc')->value('village_id');
		$survey = NeighborCouncilSurvey::where(['type'=>0,'house_id'=>$village_id])->limit(4)->get();
		// 小区新闻，最新4条
		$news = News::where(['house_id'=>$house_id])->orderBy('id','desc')->limit(4)->list()->get();
		
		$return = [
			'city'					=> $city,
			'house'					=> $house,
			'binded'				=> $binded,
			'house_id'				=> $house_id,
			'message_unview_count'	=> $message_unview_count,
			'banner'				=> $banner,
			'survey'				=> $survey,
			'news'					=> $news,
		];

		// 每次进来首页都更新当前用户的经纬度，更新地址
		if($ticket){
			ClientUserTicket::where(['ticket'=>$ticket])->update(['lat'=>$lat,'lng'=>$lng]);
		}
		return json_success('OK',$return);
	}
	//秒杀团购商品
	public function goods_list(BasicRequest $request){
	    $village_id = $request->input('village_id');
        if(!$village_id){
            return json_error('未找到地址');
        }
        $seckill_goods_list = ShopSeckillGoods::Sales()
            ->leftJoin('shop_goods_village as village','village.goods_id','=','shop_seckill_goods.id')
            ->where('village.village_id','=',$village_id)
            ->where('village.goods_type','=',1)
			->where('shop_seckill_goods.stock','>',0)
            ->Field()->limit(6)->get()->each(function($v,$k){
                $v->_detail();
                unset($v->start_time);
                unset($v->end_time);
            });
        $return['seckill']=$seckill_goods_list;
        $group_goods_list = ShopGroupGoods::Sales()
            ->leftJoin('shop_goods_village as village','village.goods_id','=','shop_group_goods.id')
            ->where('village.village_id','=',$village_id)
            ->where('village.goods_type','=',2)->Field()->limit(6)->get();
        $return['group']=$group_goods_list;
        return json_success('OK',$return);
	}
	/**
	 * @param BasicRequest $request
	 * @return array
	 *
	 */
     public function unview_message_count(BasicRequest $request){
          $count = 0;
          $ticket = $request->input('ticket');
          if($ticket) {
               $clientUserTicket = new ClientUserTicket();
               $user = $clientUserTicket->checkLogin();
               if($user->type==1|| $user->type==3){
                    $user_type=1;
               }else{
                    $user_type=2;
               }

               $message_type = ClientUserMessagesType::where(['type'=>$user_type])->get()->pluck('id');
               $count = group99(ClientUserMessage::where(['uid'=>$user->id,'viewed'=>0])->whereIn('type_id',$message_type)->count());
          }

		$return = [
			'message_unview_count'	=> $count,
		];
		return json_success('OK',$return);
	}
     //设置消息已读
     public function message_update(BasicRequest $request){

          $ticket = $request->input('ticket');

          if($ticket){
               $clientUserTicket = new ClientUserTicket();
               $user = $clientUserTicket->checkLogin();

               $type=$user->type;
               if($type==1 || $type==3){
                    $type_id=2;
               }else{
                    $type_id=7;
               }

               ClientUserMessage::where(['type_id'=>$type_id,'uid'=>$user->id,'viewed'=>0])->update(['viewed'=>1]);
               $count = group99(ClientUserMessage::where(['uid'=>$user->id,'viewed'=>0])->count());
               $return =[
                   'message_unview_count'    =>$count,
               ];

               return json_success('ok',$return);
          }else{
               return json_error('参数错误');
          }

     }
	/**
	 * 仅显示城市列表
	 */
	public function city(BasicRequest $request){
		\Validator::make($request->all(),[
			'lng'	=> 'required|numeric',
			'lat'	=> 'required|numeric',
		],[
			'lng.required'	=> '经纬度获取失败',
			'lng.numeric'	=> '经纬度格式传递不正确',
			'lat.required'	=> '经纬度获取失败',
			'lat.numeric'	=> '经纬度格式传递不正确',
		])->validate();
		$lat = $request->input('lat');
		$lng = $request->input('lng');
		$citys = collect([]);
		$city_list = [];
		DB::table('area')->select(DB::raw('id,name,merger_name,lat,lng,firstchar'))->where(['parent_id'=>0])->get()
			->each(function($v) use (&$citys){
				$city = DB::table('area')->select(DB::raw('id,name,merger_name,lat,lng,firstchar'))->where(['parent_id'=>$v->id])->get();
				$citys = $citys->merge($city);
			});
		// 按首字母排序
		$citys->sortBy('firstchar')->each(function($v) use (&$city_list){
			$city_list[$v->firstchar][] = $v;
		});
		// 当前定位城市
		$location = DB::table('area')->select(DB::raw('id,name,merger_name,lat,lng,firstchar,round(6378.138*2*asin(sqrt(pow(sin((' . $lat . '*pi()/180-lat*pi()/180)/2),2)+cos(' . $lat . '*pi()/180)*cos(lat*pi()/180)* pow(sin((' . $lng . '*pi()/180-lng*pi()/180)/2),2)))*1000) as distance'))->where(['level_type'=>2])->orderBy('distance','asc')->first();
		$return = [
			'geo'		=> $location,
			'city_list'		=> $city_list,
			'city_list_ol'	=> $citys,
		];
		return json_success('OK',$return);
	}
	
	// 城市下房屋列表
	public function city_house(IndexCityHouseRequest $request){
		$city_id = $request->input('city_id');
		$keyword = $request->input('keyword');
        $lat = $request->input('lat');	// 经
        $lng = $request->input('lng');	// 纬

		$lat_lng = DB::table('area')->select('lat','lng')->where(['id'=>$city_id])->first();
		if(empty($lat_lng) || empty($lat_lng->lat) || empty($lat_lng->lng)){
			throw new ApiException('未查到该城市详细信息');
		}

		$data = HouseDistrict::select(DB::raw('*,round(6378.138*2*asin(sqrt(pow(sin((' . $lat . '*pi()/180-' . $lat . '*pi()/180)/2),2)+cos(' . $lat . '*pi()/180)*cos(' . $lat . '*pi()/180)* pow(sin((' . $lng . '*pi()/180-' . $lng . '*pi()/180)/2),2)))*1000) as distance'))->district()->where(['city_id'=>$city_id])
			->when($keyword,function($query) use($keyword){
				$query->where('name','like','%'.$keyword.'%');
			})
			->orderBy('distance','asc')->get();
		$data->each(function($v,$k){
			$v->province = Area::where(['id'=>$v->province_id])->value('name');
			$v->city = Area::where(['id'=>$v->city_id])->value('name');
			$v->area = Area::where(['id'=>$v->area_id])->value('name');
			$v->address_full = $v->province . $v->city . $v->area . $v->address;
		});
		
		return json_success('OK',$data);
	}
	
	/**
	 * @param BasicRequest $request
	 * @return array
	 * 小区新闻列表
	 */
	public function news(BasicRequest $request){
          $this->check_login();
	     $village_id=ClientUserHouse::where('uid','=',$this->uid)->value('village_id');
		$data = News::list()->where('house_id','=',$village_id)->latest()->pages();
		return json_success('OK',$data);
	}
	
	public function news_detail(BasicRequest $request){
		$id = $request->input('id');
		$data = News::find($id);
		News::where(['id'=>$id])->increment('viewed_count');
		return json_success('OK',$data);
	}
	
	
	// 业委公示
	public function council_publicity(){
		$data = NeighborCouncilPublicity::pages();
		return json_success('OK',$data);
	}
	
	/**
	 * @param Request $request
	 * @return array
	 * 我的最后一条投诉数据
	 */
	public function council_complaints_last(Request $request){
		$this->check_login();
		$last = NeighborCouncilComplaints::where(['uid'=>$this->uid,'parent_id'=>0,'admin_uid'=>0])->orderBy('id','desc')->first();
		if($last){
			$data = $last->detail();
		}
		$data->status = $data->status ?? -1;
		return json_success('OK',$data);
	}
	
	// 添加投诉
	public function council_complaints_create(Request $request){
		$this->check_login();
		\Validator::make($request->all(),[
			'uid'			=> 'bail|required|numeric',
			'description'	=> 'bail|required|min:5',
		],[
			'uid.required'			=> '被投诉人信息必传，如无请传0',
			'description.required'	=> '请填写内容',
			'description.min'		=> '内容太少了，多写一点吧',
		])->validate();
		$parent_id = 0;
		$uid = $request->input('uid');
		$description = $request->input('description');
		// 如果未绑定房屋就不允许提交
		$exists = ClientUserHouse::where(['uid'=>$this->uid])->exists();
		if(!$exists){
			throw new ApiException('未绑定房屋暂不允许提交投诉');
		}
		$village_id=$exists['village_id'];

		// 如果新提问，就只能问一次，可追问
		/*$exist_parent = NeighborCouncilComplaints::where(['uid'=>$this->uid,'status'=>1])->orderBy('id','desc')->first();
		if($exist_parent && $exist_parent->parent_id == 0 && $exist_parent->admin_uid == 0){
			throw new ApiException('还有待处理的问题，请耐心等待回复');
		}*/
		// 如果还有未处理的投诉，直接投诉，否则新建投诉
		$exist_status = NeighborCouncilComplaints::where(['uid'=>$this->uid])->where(['uid'=>$this->uid,'parent_id'=>0,'admin_uid'=>0])->orderBy('id','desc')->value('status');
		if($exist_status == 1){
			$exist_id = NeighborCouncilComplaints::where(['uid'=>$this->uid])->where('admin_uid','!=',0)->orderBy('id','desc')->value('id');
			$parent_id = $exist_id ?: 0;
		}
		$add = [
			'uid'		=> $this->uid,
			'to_uid'	=> $uid,
			'parent_id'	=> $parent_id,
			'description'=> $description,
			'status'	=> 1,
		];
		$var = NeighborCouncilComplaints::create($add)->id;
		$push = new Push();
		$push->queue($uid,'收到新投诉信息',$description.' --请在投诉管理中处理',['type'=>'complaints_reply','complaints_id'=>0,'messages_type_id'=>7]);
		return json_return($var,'','已成功提交，请耐心等待回复');
	}
	
	// 业主投诉历史
	public function council_complaints_history(){
		$this->check_login();
		// 只查找投诉跟节点数据
		$data = NeighborCouncilComplaints::where(['uid'=>$this->uid,'parent_id'=>0,'admin_uid'=>0])->pages();
		return json_success('OK',$data);
	}
	
	// 业主投诉详情
	public function council_complaints_detail(Request $request){
		$id = $request->input('id');
		$data = NeighborCouncilComplaints::findOrFail($id)->detail();
		return json_success('OK',$data);
	}
	
	// 业主投诉业主点击完成
	public function council_complaints_complete(Request $request){
		$this->check_login();
		$status = $request->input('status',1);	// 业主满意/不满意
		$data = NeighborCouncilComplaints::where(['uid'=>$this->uid,'parent_id'=>0,'admin_uid'=>0])->orderBy('id','desc')->first();
		if($data->remarks != '系统结束服务' && $data->status != 1){
			throw new ApiException('该投诉状态为已完成，无法继续操作');
		}
		$data->status = 2;
		$data->remarks = $status ? '满意' : '不满意';
		$var= $data->save();
		// 投诉处理完成好评赠送积分
		if($status){
			ClientUserIntegral::create()->data($data->to_uid,4)->save();
		}
		return json_return($var,'','已标记完成，感谢您的配合');
	}
	
	// 获取管家上级管理员，经理
	public function council_complaints_parent(BasicRequest $request){
		$this->check_login();
		$uid = NeighborCouncilComplaints::where(['uid'=>$this->uid,'parent_id'=>0,'admin_uid'=>0])->orderBy('id','desc')->value('to_uid');
		$parent_id = ClientUserRelationship::where(['uid'=>$uid])->value('parent_id');
		$data = ClientUser::select(['mobile','username','realname','email'])->find($parent_id);
		$data->mobile = $this->user['mobile'];
		$return = [
			'type'	=> ['管家投诉','业务咨询','小区建议'],
			'parent'=> $data,
		];
		return json_return($data,'未找到此管家总经理','OK',$return);
	}
	
	// 不满意，投诉到总经理信箱
	public function council_complaints_parent_submit(IndexCouncilComplaintsParentSubmitRequest $request){
		$this->check_login();
		$uid = NeighborCouncilComplaints::where(['uid'=>$this->uid,'parent_id'=>0,'admin_uid'=>0])->orderBy('id','desc')->value('to_uid');
		$parent_id = ClientUserRelationship::where(['uid'=>$uid])->value('parent_id');
		$type = $request->input('type');
		$title = $request->input('title');
		$content = $request->input('content');
		$id = ClientUserMessage::send($parent_id,'【'.$type.'】'.$title,$content,7);
		return json_return($id,'','留言成功');
	}
	
	// 业委调查问题列表
	public function council_survey(BasicRequest $request){
		$this->check_login();
		$type = $request->input('type',0);
		if($type == 0){
			$house_id = ClientUserHouse::where(['uid'=>$this->uid])->orderBy('primary','desc')->value('village_id');
//			$organization_id = HouseDistrict::findOrFail($house_primary)->detail()->details->first()->organization_id;
//			$company_id = ServiceCompanyOrganization::where(['id'=>$organization_id])->value('company_id');
//			$join_id = $company_id;
               $data = NeighborCouncilSurvey::where(['type'=>$type,'house_id'=>$house_id])->pages()->each(function($v,$k){
                    $v->detail($this->uid);
               });
		}elseif($type == 1){
			$house_primary = ClientUserHouse::where(['uid'=>$this->uid])->orderBy('primary','desc')->value('house_id');
			$organization_id = HouseDistrict::findOrFail($house_primary)->detail()->details->first()->organization_id;
			$join_id = $organization_id;
               $data = NeighborCouncilSurvey::where(['type'=>$type,'join_id'=>$join_id])->pages()->each(function($v,$k){
                    $v->detail($this->uid);
               });
		}else{
			$join_id = 0;
               $data = NeighborCouncilSurvey::where(['type'=>$type,'join_id'=>$join_id])->pages()->each(function($v,$k){
                    $v->detail($this->uid);
               });
		}

		return json_success('OK',$data);
	}
	
	// 业委调查问题详情
	public function council_survey_detail(Request $request){
		$id = $request->input('id');
		$data = NeighborCouncilSurvey::findOrFail($id)->detail();
		return json_success('OK',$data);
	}
	
	// 业委调查提交
	public function council_survey_submit(Request $request){
		$this->check_login();
		$id = $request->input('id');
		$options_id = $request->input('options_id');
		$options_id_arr = explode(',',$options_id);
		// 是否提交过，提交过不再提交
		$exists = NeighborCouncilSurveyAnswer::where(['uid'=>$this->uid,'survey_id'=>$id])->exists();
		if($exists){
			throw new ApiException('您已参与过此调查');
		}
		$survey = NeighborCouncilSurvey::findOrFail($id)->detail();
		$var = false;
		foreach($options_id_arr as $k => $v){
			$add = [
				'uid'		=> $this->uid,
				'survey_id'	=> $id,
				'question_id'=> $survey->question->shift()->id,
				'options_id'=> $v,
				'created_at'=> time2date(),
			];
			$var = NeighborCouncilSurveyAnswer::create($add)->id;
		}
		return json_return($var,'','提交完成',['survey_id'=>$id]);
	}
	
	// 业委会章程
	public function council_list(){
		$data = NeighborCouncilList::pages();
		return json_success('OK',$data);
	}
	
	
	/**
	 * @param BasicRequest $request
	 * @return array
	 * 服务团队
	 */
	public function service_team(BasicRequest $request){
		$this->check_login();
		$uid = $this->uid;
		$primary_house = ClientUserHouse::where(['uid'=>$uid])->orderBy('primary','desc')->value('house_id');

		$organization_id = HouseDistrict::findOrFail($primary_house)->detail()->details->first()->organization_id;
		$company_id = ServiceCompanyOrganization::where(['id'=>$organization_id])->value('company_id');
		$type_id = ServiceType::where(['type'=>2,'company_id'=>$company_id])->value('id');
          $partition_id = House::where(['house_id'=>$primary_house])->value('partition_id');

		$data=collect([]);
		$image=Service::where(['type_id'=>$type_id,'parent_id'=>'0','status'=>1])->first();
          $data ['image']=($image->image);
          $service=ServiceTeam::select('name as title','id')->where(['partition_id'=>$partition_id])->get()->each(function($v,$k){
               $v->children = ServiceTeamDetail::select('mobile','img as image','name as title','real_name')->where(['team_id'=>$v->id])->get();
          });
          $data['service'] = $service;

		return json_success('OK',$data);
	}
	
	/**
	 * @param BasicRequest $request
	 * @return array
	 * APP 自动更新，根据配置来 物业版
	 */
	public function app_update_client(BasicRequest $request){
		$system = $request->input('ClientSystem');
		$version_client = $request->input('ClientVersion');
		$url = '';
		if($system == 'Android'){
			$version_last = Config::key('android_app_client_version')->value('value');
			if($version_last > $version_client){
				$url = Config::key('android_app_client_url')->value('value');
			}
		}elseif($system == 'IOS'){
			// 不需要
		}
		return json_success('OK',['description'=>'新版本更新','url'=>$url]);
	}
     /**
      * @param BasicRequest $request
      * @return json
      * 物业服务图片
      */
     public function service_image(BasicRequest $request){
          $house_id = $request->input('house_id');
          if(!$house_id) {
              $this->check_login();
              $house_id = ClientUserHouse::where(['uid' => $this->uid])->orderBy('primary', 'desc')->value('house_id');
          }
          $image = DB::table('banner')->select('name','image','url','created_at')->where(['house_id'=>$house_id,'type'=>2,'status'=>1])->get()->toArray();

          if(!$image){
               $return =[];
          }else{
               $return =$image;
          }
          return json_success('OK',$return);
     }

	/**
	 * @param BasicRequest $request
	 * @return array
	 * APP 自动更新，根据配置来 业主版
	 */
	public function app_update_company(BasicRequest $request){
		$system = $request->input('ClientSystem');
		$version_client = $request->input('ClientVersion');
		$url = '';
		if($system == 'Android'){
			$version_last = Config::key('android_app_company_version')->value('value');
			if($version_last > $version_client){
				$url = Config::key('android_app_company_url')->value('value');
			}
		}elseif($system == 'IOS'){
			// 不需要
		}
		return json_success('OK',['description'=>'检测到新版本，请更新','url'=>$url]);
	}

    /**
     * @param BasicRequest $request
     * @return array
     * APP 自动更新，根据配置来 业主版
     */
    public function app_update_store(BasicRequest $request){
        $system = $request->input('ClientSystem');
        $version_client = $request->input('ClientVersion');
        $url = '';
        if($system == 'Android'){
            $version_last = Config::key('android_app_store_version')->value('value');

            if($version_last > $version_client){
                $url = Config::key('android_app_store_url')->value('value');
            }

        }elseif($system == 'IOS'){
            // 不需要
        }
        return json_success('OK',['description'=>'检测到新版本，请更新','url'=>$url]);
    }

    //提现处理
    public function withdraw_confirm(BasicRequest $request){
        $id = $request->input('id');
        $status = $request->input('status');
        $remark = $request->input('remark');
        $withdraw = Withdraw::select('id','created_at','uid','status')->where('id','=',$id)->first();
        if(!$withdraw){
            return json_error('找不到该申请记录');
        }
        $date = date('Y-m-d',strtotime($withdraw->created_at));

        if($withdraw->status!=1){
            return json_error('提现申请已处理，请勿重复处理');
        }
        if($status==2){
            Message::message_push($withdraw->uid,'withdraw_success','您在'.$date.'的提现申请已成功,请知悉 '.$remark);
        }else if($status==3){
            Message::message_push($withdraw->uid,'withdraw_fail','您在'.$date.'的提现申请已失败,请重新申请或联系客服 '.$remark);
        }
        return json_success('OK');
    }

    public function store_confirm(BasicRequest $request){
        $store_id = $request->input('store_id');
        $status = $request->input('status');
        $remark = $request->input('remark');
        $check = ShopStore::where('id','=',$store_id)->first();
        if(!$check){
            return json_error('找不到店铺');
        }
        if($check['status']==1){
            return json_error('已审核，请勿重复操作');
        }
        $uid = ShopStore::getStoreUid($store_id);
        $mobile = ClientUser::where('id',$uid)->value('mobile');

        if($status==1){
            Message::message_push($store_id,'store_confirm_success','您的店铺审核已通过，请修改店铺基本资料以及配送设置，上架商品后即可开始正常营业',[],1);
            send_message($mobile,'审核通知',[$remark]);
        }else if($status==4){
            Message::message_push($store_id,'store_confirm_fail','您的店铺审核失败，请修改您的资料重新提交或联系客服',[],1);
            send_message($mobile,'审核失败通知',[$remark]);
        }
        return json_success('OK');
    }
}
